package com.atguigu.exercise;

/**
 *  MyDate类包含:
 * private 成员变量 year,month,day；并为每一个属性定义  getter, setter方法；
 *
 * @author : leimingchao
 * @date Date : 2021年10月06日 16:41
 */
public class MyDate implements Comparable<MyDate> {

    private int year;
    private int month;
    private int day;

    public MyDate() {
    }

    public MyDate(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    @Override
    public String toString() {
        return "MyDate{" +
                "year=" + year +
                ", month=" + month +
                ", day=" + day +
                '}';
    }

    @Override
    public int compareTo(MyDate birthday) {
        int minusYear = this.getYear() - birthday.getYear();
        if (minusYear != 0) {
            return minusYear;
        }
        int minusMonth = this.getMonth() - birthday.getMonth();
        if (minusMonth != 0) {
            return minusMonth;
        }
        return this.getDay() - birthday.getDay();
    }

    // @Override
    // public int compareTo(Object o) {
    //     if (o instanceof MyDate) {
    //         MyDate birthday = (MyDate) o;
    //         int minusYear = this.getYear() - birthday.getYear();
    //         if (minusYear != 0) {
    //             return minusYear;
    //         }
    //         int minusMonth = this.getMonth() - birthday.getMonth();
    //         if (minusMonth != 0) {
    //             return minusMonth;
    //         }
    //         return this.getDay() - birthday.getDay();
    //     }
    //     throw new RuntimeException("输入的数据类型不一致");
    //
    // }
}
